<?php
/**
 * 积分商城商品 api 接口
 * @author maniac
 */
namespace app\api\controller\v1;

use app\facade\Point AS PointFacade;

use app\facade\Members AS MembersFacade;

class Point extends Base
{
	
    /**
     * 获取积分商城商品列表
     * @param  int $category_id 商品分类 id
     * @param  int $goodsName 搜索商品名称
     */
    public function point()
    {
		$userId = $this->checkUserToken();	
		
        $type       = input('post.type/d', 0);
		
        $page       = input('post.page/d', 0);
        
        $limit      = input('post.limit/d', 0);
        
        // 上架
        $where[]    = [
        
            ['is_sale', 'eq', 1],
            
        ];
        
        switch ($type){
        	
        	case 1://推荐
        		
        		$where[]    = [
        		
        			['is_recommand', 'eq', 1],
        		
        		];
        		
        		break;
        	case 2://促销
        		
        		$where[]    = [
        		
        			['is_hot_sale', 'eq', 1],
        		
        		];
        		
        		break;
        	case 3://新品 
        		
        		$where[]    = [
        		
        			['is_latest', 'eq', 1],
        		
        		];
        		
        		break;
        }
        
        $order='is_recommand DESC,id DESC';
        
        // 分页偏移量
        $offset   = ($page - 1) * $limit;
        
        $limit    = $offset.','.$limit;
        
        $goods = PointFacade::point($where, $limit,'',$order);
        
		$point = MembersFacade::info($userId);
		
        $data = [
        
        	'point'   => $point['points'],
        	
            'data'   => $goods,
            
        ];
        
        return j(0, '获取数据成功', $data);
        
    }
    
    /**
     * 商品详情
     */
    public function detail()
    {
     	$userId = $this->checkUserToken();
        $post = input('post.');
        
        if (!$post['goods_id']) {
        	
            return j(1, '请选择商品');
            
        }
        
		//获取商品详情内容
        $where  = [
        
            'id' => $post['goods_id'],
            
        ];
        
        $info = PointFacade::detail('','',$where);
        
        $info['goods_detail'] = str_replace('src="/static/', 'src="'.config('system.attach_uri_prefix').'static/', $info['goods_detail']);
        
        if ($info) {
        	
            return j(0, '获取商品详情成功', $info);
            
        }
        
        return j(1, '获取商品信息失败');
    }
    
   
}
